<template>
	<el-drawer :title="modeName" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="选择系统" v-show="isAddSlbDo">
									<selectSystemType :parentLoadingFunction="parentLoadingFunction" :parentGetData="parentGetData" :styleData="'width:15rem;border: 1px solid red;'" :placeholderData="placeholderData"/>
								</el-form-item>
								<el-form-item label="当前系统" v-show="!isAddSlbDo">{{form.typeName}}</el-form-item>
								<el-form-item label="说明" prop="msg">
									<el-input v-model="form.msg" placeholder="请输入说明" clearable></el-input>
								</el-form-item>
								<el-form-item label="单价" prop="price">
									<el-input v-model="form.price" placeholder="请输入单价" clearable></el-input>
								</el-form-item>
								<el-form-item label="状态" prop="state">
									<el-select v-model="form.state" placeholder="状态" clearable>
										<el-option label="激活" :value="1"></el-option>
										<el-option label="失效" :value="0"></el-option>
									</el-select>
								</el-form-item>
								<el-form-item label="缴费日期" prop="jfDate">
									<el-input v-model="form.jfDate" placeholder="请输入缴费日期" clearable></el-input>
								</el-form-item>
								<el-form-item label="计价单位:" prop="priceUnit">
									<span v-if="form.priceUnit==1">终身价</span>
									<span v-if="form.priceUnit==2">年费</span>
								</el-form-item>
								<el-form-item label="其它:">
									<span>编码:{{form.sysCode}}</span>
									<span style="padding-left:20px;">版本号:{{form.theVersion}}</span>
									<span style="padding-left:20px;">最近缴费:{{form.jfLastTime}}</span>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
				<el-button type="text" size="small" @click="slb_table_del()" v-show="slb_table_del_bt">删除</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	import systemAPI from '@/api/system/systemLevelBranch';
	import selectSystemType from '@/components/glSelectCO/selectSystemType';
	export default {
		emits: ['success', 'closed'],
		components: {
		    selectSystemType
		},
		data() {
			return {
				modeName: "新增系统",
				visible: false,
				isSaveing: false,slb_table_del_bt: false,
				placeholderData: "请您选择系统",
				//表单数据
				form: {
					systemLevelBranchId: null,
					sysBranchOfficeId: null,
					systemLevelId: null,
					systemLevelTypeId: null,
					typeName: null,
					sysCode: null,
					msg: "",
					price: "",
					priceUnit: "",
					theVersion: "",
					state: "",
					jfDate: "",
					jfLastTime: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				},
				isAddSlbDo: true,
			}
		},
		mounted() {
		},
		methods: {
			//显示
			open(mode='公司',edSysBranchOfficeId){
				this.visible = true;
				if(edSysBranchOfficeId&&edSysBranchOfficeId>0){
					this.form.sysBranchOfficeId = edSysBranchOfficeId;
					this.modeName = mode+"--添加系统";
				}else{//编辑
					this.modeName = mode+"--编辑系统";
				}
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await systemAPI.systemLevelBranch.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.systemLevelBranchId = data.systemLevelBranchId;
				this.form.sysBranchOfficeId = data.sysBranchOfficeId;
				this.form.systemLevelId = data.systemLevelId;
				this.form.systemLevelTypeId = data.systemLevelTypeId;
				this.form.typeName = data.typeName;
				this.form.sysCode = data.sysCode;
				this.placeholderData = data.typeName;
				this.form.msg = data.msg;
				this.form.price = data.price;
				this.form.priceUnit = data.priceUnit;
				this.form.theVersion = data.theVersion;
				this.form.state = data.state;
				this.form.jfDate = data.jfDate;
				this.form.jfLastTime = data.jfLastTime;
				this.slb_table_del_bt = true;
				if(this.form.systemLevelBranchId>0){
					this.isAddSlbDo = false;
				}
			},
			parentLoadingFunction(loadingBz){//选择 公司  分公司 回调函数 ---- 加载提醒
				//this.showloading = loadingBz;
			},
			parentGetData(data){//选择 公司  分公司 回调函数 ---- 重新获取数据
				this.form.systemLevelId = data.systemLevelId;
				this.form.systemLevelTypeId = data.systemLevelTypeId;
				this.form.typeName = data.typeName;
				this.form.sysCode = data.sysCode;
				this.form.msg = data.msg;
				this.form.price = data.price;
				this.form.priceUnit = data.priceUnit;
				this.form.theVersion = data.theVersion;
				this.form.state = 1;
			},
			//删除
			async slb_table_del(){
			  var confirm = await this.$confirm('确定删除吗？', '提示', {
			    confirmButtonText: 'ok',
			    type: 'warning'
			  }).catch(() => {})
			  if(confirm !== 'confirm'){
			    return false;
			  }
			  var res = await systemAPI.systemLevelBranch.delete.delete(this.form.systemLevelBranchId);
			  if(res.code === 2000){
			    this.$emit('success', this.form, this.mode);
				this.visible = false;
			    this.$message.success("删除成功");
			  }else{
			    this.$alert(res.message, "提示", {type: 'error'});
			  }
			},
		}
	}
</script>
<style>
</style>
